package cn.zyq.demo.controller.h5.user;

import cn.zyq.demo.beans.user.User;
import cn.zyq.demo.service.user.UserService;
import cn.zyq.demo.system.common.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author pengdoudou
 * @Date 2023/4/20 14:43
 */
@Api(tags = "用户表")
@RestController(value = "H5UserController")
@RequestMapping(value = "/api/user")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    /**
     * 微信小程序授权登录
     *
     * @param code    请求内容
     * @return 登录结果
     */
    @ApiOperation(value = "微信小程序授权登录", response = User.class)
    @GetMapping("/wxMaLogin/{code}")
    public Object wxMaLogin(@PathVariable("code") String code) {
        return this.userService.wxMaLogin(code);
    }

    /**
     * 通过小程序获取用户手机号
     *
     * @param code
     * @return
     */
    @ApiOperation(value = "通过小程序获取用户手机号", response = User.class)
    @GetMapping("getPhone/{code}")
    public Object getPhone(@PathVariable("code") String code) {
        return this.userService.getPhone(code, this.getLoginUser());
    }

    /**
     * 更新用户头像昵称和性别等信息
     *
     * @param user   用户信息
     * @return 支付订单ID
     */
    @ApiOperation(value = "更新用户信息和相关配置", response = User.class)
    @PostMapping("updateInfo")
    public Object updateInfo(@RequestBody User user) {
        return this.userService.updateInfo(this.getLoginUser(), user);
    }

    /**
     * 获取用户信息
     *
     * @return 支付订单ID
     */
    @ApiOperation(value = "获取用户信息", response = User.class)
    @GetMapping("userInfo")
    public Object userInfo() {
        return this.getLoginUser();
    }

    /**
     * 发送短信验证码
     *
     * @param phone 手机号
     * @return
     */
    @ApiOperation(value = "发送短信验证码")
    @GetMapping("/smsCode/{phone}")
    public Object smsCode(@PathVariable("phone") String phone){
        return this.userService.smsCode(phone);
    }

    /**
     * 用户提现申请
     */
//    @ApiOperation(value = "用户提现申请")
//    @PostMapping("/withdraw")
//    public Object withdraw(@RequestBody UserCash param) {
//        log.info("用户申请提现开始{}",param);
//        User loginUser = this.getLoginUser();
//        synchronized (loginUser.getServiceID()+ "withdraw".intern()){
//            return this.userService.withdraw(param, loginUser,this.request);
//        }
//    }

}
